package sketch;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import sketch.util.Checker;
import sketch.util.SketchUtil;

public final class SClass {
	
	public final Class<?> clazz;
	
	private final List<Method> methods = new ArrayList<Method>();
	
	public SClass(Class<?> clazz) {
		Checker.checkNull(clazz, "The clazz argument could not be null.");
		this.clazz = clazz;
		this.fillinMethods();
	}
	
	private void fillinMethods() {
		Method[] ms = this.clazz.getMethods();
		for(Method m : ms) {
			if(m.getDeclaringClass().equals(Object.class)) {
				continue;
			}
			methods.add(m);
		}
	}
	
	public List<Method> getMethods() {
		return this.methods;
	}
	
	public Method findMethod(String signature) {
		for(Method method : methods) {
			if(SketchUtil.getMethodNameForSketch(method).trim().equals(signature.trim())) {
				return method;
			}
		}
		return null;
	}
	
	/**
	 * A small testing driver
	 * */
	public static void main(String[] args) {
		SClass sc = new SClass(List.class);
		for(Method m : sc.getMethods()) {
			System.out.println(m.toGenericString());
			System.out.println("  " + SketchUtil.getMethodNameForSketch(m));
		}
	}
	
}